package com.ycw.servlet.laowei;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.ycw.dao.HouseDao;
import com.ycw.dao.impl.HouseDaoImpl;
import com.ycw.pojo.House;

/**
 * Servlet implementation class ConditionSearch
 */
@WebServlet("/ConditionSearch")
public class HouseSearchByCondition extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public HouseSearchByCondition() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 通过条件查询
		HouseDao hDao = new HouseDaoImpl();

		House house = new House();
		house.setH_region(request.getParameter("hregion"));
		house.setH_shuangqi(Integer.parseInt(request.getParameter("hshuangqi")));
		house.setH_lowprice(Integer.parseInt(request.getParameter("hlowprice")));
		house.setH_highprice(Integer.parseInt(request.getParameter("hhighprice")));
		house.setSum((Integer.parseInt(request.getParameter("pageIndex")) - 1) * 10);

		List<House> resMap = hDao.getHouseByCondition(house);

		String resJSON = JSON.toJSONString(resMap);
		PrintWriter out = response.getWriter();
		out.write(resJSON);
		out.close();
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}

	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}

}
